package com.hqyj.project.service.impl;

import com.hqyj.project.dto.LeaveDto;
import com.hqyj.project.mapper.LeaveMapper;
import com.hqyj.project.service.LeaveService;
import com.hqyj.project.utils.CommonResult;
import com.hqyj.project.vo.LeaveVo;
import com.hqyj.project.vo.PageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class LeaveServiceImpl implements LeaveService {
    @Autowired
    private LeaveMapper leaveMapper;


    @Override
    public CommonResult selectInfo(LeaveDto leaveDto) {
        List<LeaveVo> leaveVos = leaveMapper.selectInfo(leaveDto);
        Integer totals = leaveMapper.selectLeaveCount(leaveDto);
        PageVo<LeaveVo> leaveVoPageVo = new PageVo<>(leaveDto.getCurrentPage(), leaveDto.getPageSize(), totals, leaveVos);
        return new CommonResult(200,"success",leaveVoPageVo);
    }

    @Override
    public CommonResult ApplyToLeave( LeaveDto leaveDto) {
        try {
            leaveMapper.applyToLeave(leaveDto);
            return new CommonResult(200,"申请已提交");
        } catch (Exception e) {
            return new CommonResult(500,"提交失败");
        }
    }

    @Override
    public CommonResult permit(String nameName) {
        try {
            leaveMapper.permit(nameName);
            return new CommonResult(200,"操作成功");
        } catch (Exception e) {
            return new CommonResult(500,"操作失败");
        }
    }

    //个人查看请假申请状态
    @Override
    public CommonResult selectPersonal(String userName) {
        try {
            List<LeaveDto> leaveDtos = leaveMapper.selectPersonalByUserName(userName);
            return new CommonResult(200,"查询成功",leaveDtos);
        } catch (Exception e) {
            return new CommonResult(500,"查询失败");
        }
    }

    @Override
    public CommonResult notPermit(String userName) {
        try {
            leaveMapper.notPermit(userName);
            return new CommonResult(200,"操作成功");
        } catch (Exception e) {
            return new CommonResult(500,"操作失败");
        }
    }

    @Override
    public CommonResult updateStart(String userName) {
        try {
            leaveMapper.updateStart(userName);
            return new CommonResult(200,"欢迎您回来,赶紧返回状态进入到工作吧");
        } catch (Exception e) {
            return new CommonResult(500,"服务器错误");
        }
    }

//    @Override
//    public CommonResult selectByLeaveStatus(String leaveStatus) {
//        List<LeaveVo> leaveVos = leaveMapper.selectByLeaveStatus(leaveStatus);
//        Integer totals = leaveMapper.selectByleaveStatus(leaveStatus);
//        PageVo<LeaveVo> leaveVoPageVo = new PageVo<>(null, null, totals, leaveVos);
//        return new CommonResult(200,"操作成功",leaveVoPageVo);
//    }


//    @Override
//    public CommonResult selectAllInfo() {
//        List<LeaveDto> leaveDtos = leaveMapper.selectLeaveByUserId();
//        return new CommonResult(200,"success",leaveDtos);
//    }
}
